/**
 * 自动引入模板，在原有 sw-precache 插件默认模板基础上做的二次开发
 *
 * 因为是自定导入的模板，项目一旦生成，不支持随 sw-precache 的版本自动升级。
 * 可以到 Lavas 官网下载 basic 模板内获取最新模板进行替换
 *
 */

/* eslint-disable */

'use strict';

var precacheConfig = [["/2023/07/21/亚托莉 Trinoline 杂谈/index.html","9157edb5256444f5bbc113fee2e6faa0"],["/2023/07/24/中二社解包神器fuckpaz/index.html","dd7a912dfa0e4b75a6c96d933fec57df"],["/2023/08/06/推荐给新人的几部galgame/index.html","d926b5c4214ba0393462a76dcfece993"],["/2023/10/08/视觉小说常用模拟器和解包工具/index.html","bdd8c9f82156b6c1358217bb5ca941a6"],["/2023/10/27/《GINKA》解包记录及作品简评/index.html","e038974812ddbd64cef5d1b2c8f48515"],["/2023/11/14/【个人学习笔记】《ambitious-mission-FD1》汉化程序记录/index.html","66fb4b782f0c670aa3324473e6082f4d"],["/2023/12/16/【怀旧向】再看一眼恋爱游戏网/index.html","05cdf4b0e1bac0487b8450ee6319e4c7"],["/2023/12/16/拥有一个自己的QQ机器人？gocq部署zerobot心得/index.html","558bf36d438684224883ff2253f51202"],["/2023/12/16/模拟器不会用？ios系统狂喜，试试云电脑推视觉小说吧!/index.html","e8c65b1105a60cd65d8cce3b55f41904"],["/2023/12/17/aurora的两个个人主页源码分享/index.html","19ba4958f71a84212993f4fe5f63a947"],["/2023/12/17/【推荐】一些催泪、深刻的galgame/index.html","8f4201abb86935788acff43db5d70a20"],["/2023/12/18/css选择器的学习笔记/index.html","e597d5eb0597053c42d2df28644ca8d3"],["/2023/12/19/Galgame-汉化破解初级教程：以-BGI-为例，从解包到测试/index.html","4b02324e9b8571dd0d1becc703fdc95f"],["/2023/12/21/【杂谈】柚子社历史/index.html","4b494a8e4c113fd28baad64671d7e8ab"],["/2023/12/24/【游戏推荐，柚子社】夏空彼方/index.html","7669494be3aad155af952a1fb8168971"],["/2023/12/24/给打算学医学类专业的人的一些建议/index.html","18691119bee60687232ab11770784ab4"],["/2023/12/25/【实践笔记】搭建alist网盘/index.html","bdb254d7277d058f3fc1e27a1d8d6047"],["/2023/12/27/【感想】使用Alist后随便写写/index.html","905664a2b3d92dd2496616523742a95d"],["/2023/12/28/【技术向】破解压缩包密码/index.html","092956092f93c948df32eb28446d8aa9"],["/2023/12/31/【实践向】樱韵建站笔记/index.html","6aadccc746481ec983c459a3c94ed769"],["/2024/01/04/替代终点的网站/index.html","7fd7918314db3509fdd286653925507e"],["/2024/01/04/非常好的搜索引擎，让我的大脑旋转/index.html","77bd0ff2b154b55fa2f4ca67cfecf35b"],["/2024/01/06/部署QQ机器人中/index.html","0dd37c9b26e09825be79e1e226f34823"],["/2024/01/10/wordpress网站一键备份/index.html","cf9cf9cad9bd9910348c03a3412e9fae"],["/2024/01/12/给自己宣传群聊。/index.html","0531aff181397fad664035c10cf66856"],["/2024/01/23/【新人向】教你玩galgame-大佬勿喷/index.html","e7a859e5307ef79b8bf03dc3e207d062"],["/2024/01/24/【1000-TB】Alist网盘/index.html","883a47931b16e28c43599dad87be19ea"],["/2024/01/27/“【抛砖引玉】找冷门同人gal的一些方法”/index.html","86b86d0dfb99aad8b7653b16d1d66721"],["/2024/01/27/【小测试】全国柚子厨选拔考试/index.html","684e765a0f3f118fbd41c3afbfe3b70c"],["/2024/01/28/【解包记录】island/index.html","3f6f4b11216776d15ec467bc2e97fa66"],["/2024/01/29/零代码开发简单游戏/index.html","ee4805f05ae540a3691106685e9512dd"],["/2024/01/31/【免费开源】AI语音合成工具——效果堪比真人/index.html","13eb8ca098260f305661bb75826e8a54"],["/2024/01/31/如何访问一些外国技术类网站/index.html","0df2fb4d26b45be139d90af31bc748ee"],["/2024/02/03/开了个在线聊天室，搭建了新的网盘/index.html","148cc4abfc0e0db9a5e1289701512461"],["/2024/02/05/island剧情分析/index.html","b0a5bf40ec3c3a8c82581dd30487dd5f"],["/2024/02/07/查看帖子隐藏内容？偷看倒卖站点帖子隐藏内容/index.html","66a683f4b6bbec807538ed335215da6e"],["/2024/02/08/浅谈国内gal资源站的困境/index.html","4a8917a3414aa533061a15d9d88675a6"],["/2024/02/10/github下载和访问慢？通过镜像站下载/index.html","ab4e6bfa3a599b3c96421890ee83a6ad"],["/2024/02/12/45个GPT-SoVits模型分享/index.html","49d82253d59543cf3bacb572aa13fdbf"],["/2024/02/12/魔法分享/index.html","487a138deb0f98c2aad412d782911de0"],["/2024/02/13/零成本建站：免费搭建一个自己的网站（一）/index.html","82dca3bcf3f6b5b4194fd221ae88e48d"],["/2024/02/14/零成本建站：免费搭建一个自己的网站（二）/index.html","47178f41e16ce8897f04e5c6868a2720"],["/2024/02/15/“一块钱建了个资源站”/index.html","fbc7ac628970a0aa04d13fed80dcf276"],["/2024/02/15/【资源转交】曾经的资源转交给隔壁站/index.html","f4d0bfd9846d4d9946f37f394f7d386e"],["/2024/02/17/【杂谈】大学是什么样的？一些杂谈/index.html","4ebc9754198f62edb59108389dfc47ba"],["/2024/02/17/【资源网站推荐】帮隔壁宣站/index.html","1d0d4f5d686bea965d65dacbdde7d2b6"],["/2024/02/17/如何管理多个博客网站/index.html","4c6415f5ddffa63e8c69bba9bdffa62c"],["/2024/02/25/hexo加密插件分享/index.html","18a9ae3b32db051a26e81db27e12eb58"],["/2024/02/27/感觉-可能要留级了/index.html","e6eb725e1d565bcc4ce57d59dd4d5ad2"],["/2024/02/28/python/index.html","dd57f6cd61c099ca5de7486d3536b773"],["/2024/02/29/python第七天/index.html","1ec2876dcae72f4abb6ba9e7480a4967"],["/2024/02/29/“人上人”入门教程/index.html","17f4fb3ee8404e66d4a5051a4dcda6e7"],["/2024/02/29/制作Galgame-——lightvn引擎教程(一)/index.html","851c757388e2da744459295c231d198f"],["/2024/03/02/【制作视觉小说】lightvn引擎学习/index.html","45fe6aa1847a18bfde382554d572b036"],["/2024/03/07/心理普查-一定要遵循形式主义/index.html","a22ec97792e4e2d6407791344617ee6c"],["/2024/03/14/群内小游戏制作中/index.html","35c6f27a17d82b8d5dc8bde1918623e8"],["/2024/03/17/参与gal开发工作/index.html","2187519e8c2a233a97529daa792f4edc"],["/2024/03/21/3-21随记/index.html","e8f670257802ec4ba4abee86b49ff2be"],["/2024/03/23/【杂谈】关于亚托莉动画化/index.html","face99ded02a22a87387032fa0cf4bde"],["/2024/03/24/3-24倒垃圾/index.html","6a1d04d3f89743cce963ab5d1d96d962"],["/2024/03/29/水仙十周年杂谈/index.html","03963d9d33246683caab1c4d056c440b"],["/2024/04/06/自己写的light-vn引擎教程合集/index.html","e9252cbcc22f94be11f0cc773c0c3620"],["/2024/04/08/【杂谈向】最喜欢的几部galgame/index.html","0517de387e824cebadcdd609170fa02c"],["/2024/04/09/为什么我讨厌“大佬”？/index.html","4418474f4b7937bf12adc6644a15e671"],["/2024/04/15/四月小记/index.html","31773979fe0bb3edf015a2e8a6347046"],["/2024/04/20/《以美丽中国建设全面推进人与自然和谐共生的现代化》/index.html","17ba4ff141ad60151a7df3da31987bbb"],["/2024/04/21/分享几部拯救电子养胃的galgame/index.html","d8ba79930b61a563f39547ef73c84674"],["/2024/04/21/网购35块钱手机被坑-坚持维权/index.html","f5ea2fd72fba730e7890b01a5d011bb9"],["/2024/04/26/【闲聊向】人情世故、为人处世/index.html","674a1d97df8eef00cee736dbbc3056d7"],["/2024/04/29/随便写写/index.html","ac7d04d9e7f4d198bc66bbbb1911e8af"],["/2999/02/26/【置顶帖】资源去哪下载？域名通知/index.html","da88dd05d9909b2a296665a42148e0b8"],["/404.html","062dcefa30d8c46828627703f9bdfa09"],["/about/index.html","d0868e06cacb7a0cf609adb6365a014f"],["/archives/2023/07/index.html","beaca0c5446daf74897f9d4aa35f45f8"],["/archives/2023/08/index.html","711ab21e5be5e97eed618de7c067e6d3"],["/archives/2023/10/index.html","36fa46dee832e99ed90c7e4ae5abcb27"],["/archives/2023/11/index.html","c8eed270f4fb5f8bb1974b47803e5ce8"],["/archives/2023/12/index.html","c872be87a63defff0b68c853c9b626c6"],["/archives/2023/12/page/2/index.html","1f7824714cde9434ab72b1a59c044d82"],["/archives/2023/index.html","54447fd416511c20c28ef09a6734cf30"],["/archives/2023/page/2/index.html","31caedf5e518b597525f17e810ed88e3"],["/archives/2024/01/index.html","3a65a265bad4f0a36f81ad5c3f966cf1"],["/archives/2024/01/page/2/index.html","31981381ee71d0278f5f089f2b0f5f13"],["/archives/2024/02/index.html","dfce31c665b531d75538aa195390217e"],["/archives/2024/02/page/2/index.html","bffaca23d2d5b8aa7460211db3d43570"],["/archives/2024/03/index.html","bcbd2bfab0fa03aff03d238e7aec806a"],["/archives/2024/04/index.html","71afd23616f0dbf26aaf57fd7bfd1e1c"],["/archives/2024/index.html","a99623251fa5a5e546d58909526f6dc9"],["/archives/2024/page/2/index.html","0a90e9ed276d7a73f404feb3df955de3"],["/archives/2024/page/3/index.html","36fbad7c915739640686f35134747202"],["/archives/2024/page/4/index.html","8ac3efbe8499c06753e7c718457cc856"],["/archives/2024/page/5/index.html","8748f8ddb2bb17b3068cec6f40eb0ac5"],["/archives/2999/02/index.html","690746d2fcd50d0ebe233d71e4948614"],["/archives/2999/index.html","b01abbf6cc9cc3b2a45af02ba15b8141"],["/archives/index.html","e981b4648ae5aff4c6cffc49df3b98b3"],["/assets/wallpaper-2311325.jpg","6f01af8d24d6d2de2564af30c32366b7"],["/assets/wallpaper-2572384.jpg","3637ba36e2daaeaa2bb438f65b0bff9c"],["/assets/wallpaper-878514.jpg","2bf9e4c5bf4f5fec55353a46bd3176c6"],["/categories/index.html","40c95a019d9f39e533ac3e343915295d"],["/css/app.css","3a075c81d2898978830560c259f8128e"],["/css/comment.css","bd967f589b271e0724a86fec0bd55808"],["/css/mermaid.css","c66db1b09a670a8a932f5941155d4d4b"],["/friends/index.html","3f24e3a9f57521f32672eebf473ac045"],["/images/404.png","52d6ca721e50bf3fd2f09e0d2ebe6f6c"],["/images/algolia_logo.svg","88450dd56ea1a00ba772424b30b7d34d"],["/images/apple-touch-icon.png","c7e8e0062b8300b2134e6ae905db522b"],["/images/avatar.jpg","b9ff7701104855bf86af8504d455e7ec"],["/images/logo.svg","e67639a80e9511587a08359bc7740624"],["/images/play_disc.png","13a96370213881a22cfaa05bcaf1953c"],["/images/play_needle.png","ed199c599562491c1c27de4a8f3daa6f"],["/images/search.png","e576cdbf6d4df3f4587202d4795e0887"],["/images/wechatpay.png","b3e68042b2263757df68d1be2cfe9ea3"],["/index.html","15f3708f604bfc74a063352c4f47debf"],["/js/app.js","819e4370030da5a398a0396e97e2bab0"],["/liaotian/index.html","661afb711168b7f71db7302bb2bb8ac4"],["/liuyan/index.html","5d42ad3fe799bb9166f45d30174f7ad1"],["/page/2/index.html","99a3158e54db7ac0109a64610e33be86"],["/page/3/index.html","20892da1e5f7296bd3447063564acbfd"],["/page/4/index.html","04003d23a43ecf4d8d51152ee522e985"],["/page/5/index.html","c642b0cd414d00fb5a5a28f679301f9c"],["/page/6/index.html","e11fc6c31e0e8366d01aa50bdf8ec717"],["/page/7/index.html","659778ac226ec0c5e8d525786fe1845e"],["/page/8/index.html","b1a727c29f884f801da24059f128efa3"],["/sw-register.js","552b9e6980c78facd9d8e39918fef72a"],["/tags/QQ机器人/index.html","2bf0179c96f20fb1e0f28bf1030ad8a0"],["/tags/gal工具/index.html","b57817e5c7e6af20fdb9e4a8a5f7ea0f"],["/tags/gal测评/index.html","d8661a05e6bcbec9f99895bc03383a8d"],["/tags/index.html","3e3a4ce9a10735f8e76e36194e68a88a"],["/tags/技术向/index.html","a7f3759cfa68bc5cebcb11d9614e1f6f"],["/tags/推荐/index.html","4a2fc22d5e10ecb9a67d8da2f97a997d"],["/tags/视觉小说工具/index.html","e0bee8ba22ccd39eab24984eb400b406"],["/tags/视觉小说技术/index.html","d7795344269ee3c52e1d0950f17ea3d3"],["/tags/视觉小说技术，视觉小说测评/index.html","6632988990ff70b4df87bc798e8b25dc"]];
var cacheName = 'sw-precache-v3--' + (self.registration ? self.registration.scope : '');
var firstRegister = 1; // 默认1是首次安装SW， 0是SW更新


var ignoreUrlParametersMatching = [/^utm_/];


var addDirectoryIndex = function (originalUrl, index) {
    var url = new URL(originalUrl);
    if (url.pathname.slice(-1) === '/') {
        url.pathname += index;
    }
    return url.toString();
};

var cleanResponse = function (originalResponse) {
    // 如果没有重定向响应，不需干啥
    if (!originalResponse.redirected) {
        return Promise.resolve(originalResponse);
    }

    // Firefox 50 及以下不知处 Response.body 流, 所以我们需要读取整个body以blob形式返回。
    var bodyPromise = 'body' in originalResponse ?
        Promise.resolve(originalResponse.body) :
        originalResponse.blob();

    return bodyPromise.then(function (body) {
        // new Response() 可同时支持 stream or Blob.
        return new Response(body, {
            headers: originalResponse.headers,
            status: originalResponse.status,
            statusText: originalResponse.statusText
        });
    });
};

var createCacheKey = function (originalUrl, paramName, paramValue,
    dontCacheBustUrlsMatching) {

    // 创建一个新的URL对象，避免影响原始URL
    var url = new URL(originalUrl);

    // 如果 dontCacheBustUrlsMatching 值没有设置，或是没有匹配到，将值拼接到url.serach后
    if (!dontCacheBustUrlsMatching ||
        !(url.pathname.match(dontCacheBustUrlsMatching))) {
        url.search += (url.search ? '&' : '') +
            encodeURIComponent(paramName) + '=' + encodeURIComponent(paramValue);
    }

    return url.toString();
};

var isPathWhitelisted = function (whitelist, absoluteUrlString) {
    // 如果 whitelist 是空数组，则认为全部都在白名单内
    if (whitelist.length === 0) {
        return true;
    }

    // 否则逐个匹配正则匹配并返回
    var path = (new URL(absoluteUrlString)).pathname;
    return whitelist.some(function (whitelistedPathRegex) {
        return path.match(whitelistedPathRegex);
    });
};

var stripIgnoredUrlParameters = function (originalUrl,
    ignoreUrlParametersMatching) {
    var url = new URL(originalUrl);
    // 移除 hash; 查看 https://github.com/GoogleChrome/sw-precache/issues/290
    url.hash = '';

    url.search = url.search.slice(1) // 是否包含 '?'
        .split('&') // 分割成数组 'key=value' 的形式
        .map(function (kv) {
            return kv.split('='); // 分割每个 'key=value' 字符串成 [key, value] 形式
        })
        .filter(function (kv) {
            return ignoreUrlParametersMatching.every(function (ignoredRegex) {
                return !ignoredRegex.test(kv[0]); // 如果 key 没有匹配到任何忽略参数正则，就 Return true
            });
        })
        .map(function (kv) {
            return kv.join('='); // 重新把 [key, value] 格式转换为 'key=value' 字符串
        })
        .join('&'); // 将所有参数 'key=value' 以 '&' 拼接

    return url.toString();
};


var addDirectoryIndex = function (originalUrl, index) {
    var url = new URL(originalUrl);
    if (url.pathname.slice(-1) === '/') {
        url.pathname += index;
    }
    return url.toString();
};

var hashParamName = '_sw-precache';
var urlsToCacheKeys = new Map(
    precacheConfig.map(function (item) {
        var relativeUrl = item[0];
        var hash = item[1];
        var absoluteUrl = new URL(relativeUrl, self.location);
        var cacheKey = createCacheKey(absoluteUrl, hashParamName, hash, false);
        return [absoluteUrl.toString(), cacheKey];
    })
);

function setOfCachedUrls(cache) {
    return cache.keys().then(function (requests) {
        // 如果原cacheName中没有缓存任何收，就默认是首次安装，否则认为是SW更新
        if (requests && requests.length > 0) {
            firstRegister = 0; // SW更新
        }
        return requests.map(function (request) {
            return request.url;
        });
    }).then(function (urls) {
        return new Set(urls);
    });
}

self.addEventListener('install', function (event) {
    event.waitUntil(
        caches.open(cacheName).then(function (cache) {
            return setOfCachedUrls(cache).then(function (cachedUrls) {
                return Promise.all(
                    Array.from(urlsToCacheKeys.values()).map(function (cacheKey) {
                        // 如果缓存中没有匹配到cacheKey，添加进去
                        if (!cachedUrls.has(cacheKey)) {
                            var request = new Request(cacheKey, { credentials: 'same-origin' });
                            return fetch(request).then(function (response) {
                                // 只要返回200才能继续，否则直接抛错
                                if (!response.ok) {
                                    throw new Error('Request for ' + cacheKey + ' returned a ' +
                                        'response with status ' + response.status);
                                }

                                return cleanResponse(response).then(function (responseToCache) {
                                    return cache.put(cacheKey, responseToCache);
                                });
                            });
                        }
                    })
                );
            });
        })
            .then(function () {
            
            // 强制 SW 状态 installing -> activate
            return self.skipWaiting();
            
        })
    );
});

self.addEventListener('activate', function (event) {
    var setOfExpectedUrls = new Set(urlsToCacheKeys.values());

    event.waitUntil(
        caches.open(cacheName).then(function (cache) {
            return cache.keys().then(function (existingRequests) {
                return Promise.all(
                    existingRequests.map(function (existingRequest) {
                        // 删除原缓存中相同键值内容
                        if (!setOfExpectedUrls.has(existingRequest.url)) {
                            return cache.delete(existingRequest);
                        }
                    })
                );
            });
        }).then(function () {
            
            return self.clients.claim();
            
        }).then(function () {
                // 如果是首次安装 SW 时, 不发送更新消息（是否是首次安装，通过指定cacheName 中是否有缓存信息判断）
                // 如果不是首次安装，则是内容有更新，需要通知页面重载更新
                if (!firstRegister) {
                    return self.clients.matchAll()
                        .then(function (clients) {
                            if (clients && clients.length) {
                                clients.forEach(function (client) {
                                    client.postMessage('sw.update');
                                })
                            }
                        })
                }
            })
    );
});



    self.addEventListener('fetch', function (event) {
        if (event.request.method === 'GET') {

            // 是否应该 event.respondWith()，需要我们逐步的判断
            // 而且也方便了后期做特殊的特殊
            var shouldRespond;


            // 首先去除已配置的忽略参数及hash
            // 查看缓存简直中是否包含该请求，包含就将shouldRespond 设为true
            var url = stripIgnoredUrlParameters(event.request.url, ignoreUrlParametersMatching);
            shouldRespond = urlsToCacheKeys.has(url);

            // 如果 shouldRespond 是 false, 我们在url后默认增加 'index.html'
            // (或者是你在配置文件中自行配置的 directoryIndex 参数值)，继续查找缓存列表
            var directoryIndex = 'index.html';
            if (!shouldRespond && directoryIndex) {
                url = addDirectoryIndex(url, directoryIndex);
                shouldRespond = urlsToCacheKeys.has(url);
            }

            // 如果 shouldRespond 仍是 false，检查是否是navigation
            // request， 如果是的话，判断是否能与 navigateFallbackWhitelist 正则列表匹配
            var navigateFallback = '';
            if (!shouldRespond &&
                navigateFallback &&
                (event.request.mode === 'navigate') &&
                isPathWhitelisted([], event.request.url)
            ) {
                url = new URL(navigateFallback, self.location).toString();
                shouldRespond = urlsToCacheKeys.has(url);
            }

            // 如果 shouldRespond 被置为 true
            // 则 event.respondWith()匹配缓存返回结果，匹配不成就直接请求.
            if (shouldRespond) {
                event.respondWith(
                    caches.open(cacheName).then(function (cache) {
                        return cache.match(urlsToCacheKeys.get(url)).then(function (response) {
                            if (response) {
                                return response;
                            }
                            throw Error('The cached response that was expected is missing.');
                        });
                    }).catch(function (e) {
                        // 如果捕获到异常错误，直接返回 fetch() 请求资源
                        console.warn('Couldn\'t serve response for "%s" from cache: %O', event.request.url, e);
                        return fetch(event.request);
                    })
                );
            }
        }
    });









/* eslint-enable */
